package cn.com.huzo.repository.purchase.impl;

import cn.com.huzo.model.entities.purchase.NotesPayabledLinesPoStockInEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.purchase.NotesPayabledLinesPoStockInRepository;
import java.util.ArrayList;

/**
 * 对账单明细-到货情况数据访问对象。
 *
 * @author 吴旭
 */
@Repository("NotesPayabledLinesPoStockInRepository")
public class NotesPayabledLinesPoStockInRepositoryImpl extends GenericRepositoryImpl<NotesPayabledLinesPoStockInEntity, String>
        implements NotesPayabledLinesPoStockInRepository {

    private final String namespace = "cn.com.huzo.repository.purchase.NotesPayabledLinesPoStockInRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public NotesPayabledLinesPoStockInRepositoryImpl() {
        super(NotesPayabledLinesPoStockInEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<NotesPayabledLinesPoStockInEntity> fetchByHeaderKey(Map<String, Object> criterion) {        
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByKey"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<NotesPayabledLinesPoStockInEntity> fetchAccountPayable(Map<String, Object> criterion) {
        List<NotesPayabledLinesPoStockInEntity> _result = new ArrayList();

        // 0:正常对账用 1：强制对账用
        if ((Integer) criterion.get("Flag") == 0) {
            _result = getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                    namespace, "fetchForNormalData"), criterion);
        } else {
            _result = getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                    namespace, "fetchForHandCutData"), criterion);
        }

        return _result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<NotesPayabledLinesPoStockInEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insert(Map<String, Object> criterion) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchDelete(List<NotesPayabledLinesPoStockInEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchDelete"), itemList);
    }
}
